package com.atguigu.spzx.pay.controller;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradeWapPayModel;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.atguigu.spyx.model.common.Result;
import com.atguigu.spyx.model.common.ResultCodeEnum;
import com.atguigu.spyx.model.common.com.atguigu.spyx.model.entity.order.OrderInfo;
import com.atguigu.spyx.model.exception.SpzxException;
import com.atguigu.spzx.order.api.OrderClient;
import com.atguigu.spzx.pay.config.AlipayConfig;
import com.atguigu.spzx.pay.service.AplipayService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author LT
 * @create 2023-11-22-20:59
 */
@Controller
@Slf4j
@RequestMapping("/api/order/alipay")
public class AplipayController {
    @Resource
    OrderClient orderClient;
    @Resource
    AplipayService aplipayService;

    @PostMapping("notifyUrl")
    public String notifyUrl(@RequestParam Map<String,String> params){
        return aplipayService.notifyUrl(params);
    }

    @GetMapping("returnUrl")
    public String returnUrl(@RequestParam Map<String,String> params){
        return aplipayService.returnUrl(params);
    }

    //阿里pay
    @GetMapping("/submitAlipay/{orderNo}")
    @ResponseBody
    public Result submitAlipay (@PathVariable("orderNo")Long orderNo){
        String form  = aplipayService.submitAlipay(orderNo);
        System.out.println(form);
        return Result.ok().data(form);
    }
}
